package com.wf.course.web.controller.comm;

import com.wf.course.model.comm.AppVersion;
import com.wf.course.service.IAppVersionService;
import com.wf.course.web.Constants;
import com.wf.course.web.OSSUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * app版本信息修改
 */
@Controller
@RequestMapping("app/version")
public class AppVersionController {

    private Logger logger = LoggerFactory.getLogger(AppVersionController.class);

    @Autowired
    private IAppVersionService appVersionService;

    @RequestMapping("list")
    public String list(Model model) {
        model.addAttribute("results", appVersionService.list());
        return "comm/appVersionList";
    }

    @RequestMapping("update")
    public String update(AppVersion model) {
        appVersionService.update(model);
        return "redirect:/app/version/list";
    }

    @ResponseBody
    @RequestMapping("upload")
    public Map upload(MultipartFile file){
        try {
            String uuid = OSSUtil.addFileCopy(file, "android_file", Constants.IGM_BUCKET);
            logger.error("android rpk upload: " + uuid);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        Map<String, String> map = new HashMap<>();
        map.put("msg", "上传成功");
        return map;
    }
}
